/*
 * @Author: Starfish_DL
 * @Date: 2020-09-27 11:45:57
 * @LastEditors: Starfish_DL
 * @LastEditTime: 2020-09-28 12:22:21
 * @CurrentVersion: 1.0
 * @Description: 
 */
#include<iostream>
#include<string>
using namespace std;
class iStackLinkNode
{
public:
    int data;
    iStackLinkNode *next;
    iStackLinkNode(/* args */);
    ~iStackLinkNode();
};

iStackLinkNode::iStackLinkNode()
{
    data=0;
    next=nullptr;
}

iStackLinkNode::~iStackLinkNode()
{
}

class cStackLinkNode
{
public:
    char data;
    cStackLinkNode *next;
    cStackLinkNode();
    ~cStackLinkNode();
};

cStackLinkNode::cStackLinkNode()
{
    data='0';
    next=nullptr;
}

cStackLinkNode::~cStackLinkNode()
{
}

class iStackLink
{
    //done the class of linkstack has finished.
public:
    iStackLinkNode *s;
    iStackLink(/* args */);
    void Push(int e);
    int Pop();
    int GetTop();
    ~iStackLink();
};

iStackLink::iStackLink()
{
    s=new iStackLinkNode();
}

iStackLink::~iStackLink()
{
    iStackLinkNode *pre=s->next,*p=s;
    while (pre!=nullptr)
    {
        delete p;
        p=pre;
        pre=pre->next;
    }
    delete p;
}

void iStackLink::Push(int e)
{
    //done function of pushing has finished.
    iStackLinkNode *pre=new iStackLinkNode();
    pre->next=s->next;
    s->next=pre;
    pre->data=e;
}

int iStackLink::Pop()
{
    iStackLinkNode *p=s->next;
    int e=p->data;
    s->next=p->next;
    delete p;
    return e;
}

int iStackLink::GetTop()
{
    return (s->next->data);
}

void dispstack(iStackLink *L)
{
    iStackLinkNode *p=L->s->next;
    while (p!=nullptr)
    {
        cout<<p->data<<" ";
        p=p->next;
    }
    cout<<endl;
}

class cStackLink
{
    //done the class of linkstack has finished.
public:
    cStackLinkNode *s;
    cStackLink();
    void Push(char e);
    char Pop();
    char GetTop();
    ~cStackLink();
};

cStackLink::cStackLink()
{
    s=new cStackLinkNode();
}

cStackLink::~cStackLink()
{
    cStackLinkNode *pre=s->next,*p=s;
    while (pre!=nullptr)
    {
        delete p;
        p=pre;
        pre=pre->next;
    }
    delete p;
}

void cStackLink::Push(char e)
{
    //done function of pushing has finished.
    cStackLinkNode *pre=new cStackLinkNode();
    pre->next=s->next;
    s->next=pre;
    pre->data=e;
}

char cStackLink::Pop()
{
    if (s->next==nullptr)
    {
        return '0';
    }
    cStackLinkNode *p=s->next;
    char e=p->data;
    s->next=p->next;
    delete p;
    return e;
}

char cStackLink::GetTop()
{
    return (s->next->data);
}

bool match(string exp,int n)
{
    cStackLink *slink=new cStackLink();
    int i=0;
    while (i<n)
    {
        if (exp[i]=='(')
        {
            slink->Push(exp[i]);
        }
        else if (exp[i]==')')
        {
            if (slink->s->next==nullptr)
            {
                return false;
            }
            slink->Pop();
        }
        i++;
    }
    if (slink->s->next==nullptr)
    {
        return true;
    }
    else
    {
        return false;
    }
}

int main(int argc, char const *argv[])
{
    //done the main function has finished.
    //iStackLink *s=new iStackLink();
    string str1="The((class)is(true)";
    cout<<match(str1,str1.length())<<endl;
    // int a[6]={1,3,4,5,7,8};
    // for (int i = 0; i < 6; i++)
    // {
    //     s->Push(a[i]);
    // }
    // dispstack(s);
    // cout<<s->GetTop()<<endl;
    // for (int k = 0; k < 2; k++)
    // {
    //     s->Pop();
    // }
    // dispstack(s);
    // cout<<s->GetTop()<<endl;
    //delete s;
    return 0;
}
